<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="directive.jsp" />
<%-- fist time, not postback --%>
<c:if test="${!empty param.username}">
    <c:choose>
        <c:when test="${param.password == param.passwordConfirm}">
            <%-- create account --%>
            <jsp:useBean id="custMan" class="com.aal.model.CustomerManagement"/>
            <jsp:setProperty name="custMan" property="username" value="${param.username}"/>
            <jsp:setProperty name="custMan" property="password" value="${param.password}"/>
            <jsp:setProperty name="custMan" property="customergroupId" value="${1}"/><%--normal group --%>
            <jsp:setProperty name="custMan" property="firstname" value="${param.firstname}"/>
            <jsp:setProperty name="custMan" property="lastname" value="${param.lastname}"/>
            <jsp:setProperty name="custMan" property="email" value="${param.email}"/>
            <jsp:setProperty name="custMan" property="phone" value="${param.phone}"/>
            <jsp:setProperty name="custMan" property="billingaddress" value="${param.billingAddress}"/>
            <c:choose>
                <c:when test="${custMan.createuser == true}">
                    <c:set var="message" value="User created successfully, you can log in now!"/>
                </c:when>
                <c:otherwise>
                    <c:set var="message" value="Error while trying to access database!"/>
                </c:otherwise>
            </c:choose>
        </c:when>
        <c:otherwise>
            <%-- error --%>
            <c:set var="message" value="Passwords are not the same!"/>
        </c:otherwise>
    </c:choose>
</c:if>

<jsp:include page="header.jsp" />

    <div id="inner_wrap">
	<div id="inner_hold">
	<div id="inner">
	<div class="center_hold">
    <div class="big_padding">
		<div class="big_blue">
			<table width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td valign="top">
						<div class="listing_star">
							<h1 class="blue_sep_bot">Create an AAL account</h1>
							<div id="d_reg2" class="memty">
                                <c:if test="${!empty message}">
                                    <p style="color:red"><strong>Attention:</strong> ${message}</p>
                                </c:if>
                                
								<div id="form_big" class="f11">
									<form action="register.jsp" method="post">

									<div><label for="username">Username</label></div>
                                    <p><input name="username" type="text" class="sinput" maxlength="25" value="" placeholder="Enter your desired username" required/></p>
									<p class="f11_blue" style="padding: -4px 0 5px 0">^ Username can only contain a-z, A-Z, 0-9 and space</p>

									<div><label for="email">Email Address</label></div>
                                    <p><input name="email" type="text" class="sinput" value="" type="email" placeholder="Enter your email" required/></p>
									<p class="f11_blue" style="padding: -4px 0 5px 0">^ Please double check your email</p>

									<div><label for="password">Password</label></div>
									<p><input name="password" type="password" class="sinput" placeholder="Enter your password" required /></p>

									<div><label for="passwordConfirm">Confirm Password</label></div>
									<p><input name="passwordConfirm" type="password" class="sinput" placeholder="Confirm your password" required/></p>

									<div><label for="firstname">First Name</label></div>
									<p><input name="firstname" type="text" class="sinput" value="" placeholder="Enter your first name" required/></p>
									
									<div><label for="lastname">Last Name</label></div>
									<p><input name="lastname" type="text" class="sinput" value="" placeholder="Enter your last name" required/></p>

									<div><label for="gender">Gender</label></div>
									<p class="f14_arial"><input name="gender" type="radio" value="0" checked="checked" /> Male &nbsp;&nbsp; <input name="gender" type="radio" value="1" /> Female</p>

									<div><label for="billingAddress">Billing Address</label></div>
                                    <p><textarea name="billingAddress" rows="4" class="sinput" placeholder="Enter your billing address here"></textarea></p>
                                    
                                    <div><label for="phone">Phone</label></div>
									<p><input name="phone" type="text" class="sinput" value="" type="number" required/></p>
									<p class="f11_blue" style="padding: -4px 0 5px 0">^ Please double check your phone</p>

									<div class="blue_sep" style="margin-top: 20px">
										<p style="padding: 5px 0"><input type="checkbox" value="1" id="s_newsletter" checked="checked" /> &nbsp; Send me e-updates for new products, <strong>SALES</strong> and <strong>exclusive stuff</strong>!</p>
									</div>

									<div class="blue_sep">
										<p><input type="submit" id="submit" class="but_join" value="Register me!" /></p>
										<p class="empty"></p>
									</div>
									</form>
								</div>
							</div>
						</div>
					</td>
					<td width="130">&nbsp;</td>
					<td width="230" valign="top">
						<div id="loginbox">
							<h3>Members Login</h3>

							<form action="login.jsp" method="post">
								<div><label for="username">Username</label></div>
                                <p><input type="text" name="username" id="username" maxlength="255" class="sinput" style="width: 180px" placeholder="Enter your username" required /></p>

								<div><label for="password">Password</label></div>
                                <p style="margin-bottom: 15px"><input type="password" name="password" id="password" maxlength="32" class="sinput" style="width: 180px" placeholder="Enter your password" required /></p>

								<div>
									<input type="submit" id="login" class="but_login" value="Login to AAL" />
								</div>
							</form>

							<div class="blue_sep"><a href="reset-password.jsp" rel="nofollow" class="blue">Forgot Your <strong>Password</strong>?</a></div>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	</div>
	</div>
	</div>
	</div>

<jsp:include page="footer.jsp" />